﻿using KingApp.Common;
using KingApp.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KingApp.DB
{
    public sealed class SourceData
    {
        private static SourceData instance;
        private static object syncLock = new object();
        private List<Lottery> lotterys;

        private List<Lottery> testLotterys;

        private SourceData()
        {
            var index = 1;
            lotterys = CombinationHelper.GetCombinations(5, 11)
                .Select(c => new Lottery
                {
                    Id = index++,
                    LotteryNumber = string.Join(",", c.Select(l => l.ToString("00")).ToArray())
                })
                .ToList();
        }

        /// <summary>
        ///  验证 数据
        /// </summary>
        public List<Lottery> TestLotterys
        {
            get
            {
                return this.testLotterys;
            }
            set
            {
                this.testLotterys = value;
            }
        }

        public List<Lottery> Lotterys
        {
            get
            {
                return this.lotterys;
            }
        }

        public static SourceData GetInstance()
        {
            if (instance == null)
            {
                lock (syncLock)
                {
                    if (instance == null)
                    {
                        instance = new SourceData();
                    }
                }
            }

            return instance;
        }

        public static void ClearInstance()
        {
            instance = null;
        }

    }

}
